const https = require('https');
const fs = require('fs');

const imageUrl = 'https://example.com/image.jpg';
const imagePath = './image.jpg';

https.get(imageUrl, (response) => {
  const fileStream = fs.createWriteStream(imagePath);
  response.pipe(fileStream);
  fileStream.on('finish', () => {
    console.log(`Image downloaded to ${imagePath}`);
  });
}).on('error', (error) => {
  console.error(`Error downloading image: ${error}`);
});